from flask_restful import Resource
from flask_restful.reqparse import RequestParser

from libs.jwt_token import authenticate


class TokenView(Resource):
    """
    登录生成token
    """

    parser = RequestParser()
    parser.add_argument('username', type=str, required=True)
    parser.add_argument('password', type=str, required=True)

    def post(self):
        params = self.parser.parse_args()
        return authenticate(params['username'], params['password'])
